/**
 * 
 */
package com.imooc.security.core;

import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.imooc.security.core.properties.SecurityProperties;
import org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter;
import org.springframework.util.AntPathMatcher;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhailiang
 *
 */
@Configuration
@EnableConfigurationProperties(SecurityProperties.class)
public class SecurityCoreConfig {
//    RememberMeAuthenticationFilter
    private static List<String> authList = new ArrayList<>();

    private static AntPathMatcher  antPathMatcher = new AntPathMatcher();

    static {
        authList.add("a.b");
        authList.add("a.a");
        authList.add("a.*");
    }

    public static void main(String[] args) {
        // 加入权限字符串到Auths
        /*String[] opers = "a.b.c.d,e.d".split("[,]");

        for (String oper : opers) {
            String[] mods = oper.split("[.]");
            if (mods.length <= 2) {
                if(!authList.contains(oper)){
                    authList.add(oper);
                }
            } else {
                String action = mods[0];
                for (int i = 1; i < mods.length; i++) {
                    if(!authList.contains(action + "." + mods[i])){
                        authList.add(action + "." + mods[i]);
                    }
                }
            }
        }*/

      //  s("a.c");
        System.out.println(match());

    }

    public static boolean s(String auth){

        String action = auth.split("[.]")[0];
        System.out.println("front "+authList.contains(auth));
        System.out.println("back "+authList.contains(action + ".*"));
        return authList.contains(auth) || authList.contains(action + ".*");

    }

    public static boolean match(){
        boolean flag = antPathMatcher.match("/q","aa");
        return flag;
    }
}
